﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Calculation : Form
    {
        public Calculation()
        {
            InitializeComponent();
        }

        public void StrToInt(int[] intarr, string[] strarr)
        {
            for (int i = 0; i < strarr.Length; i++)
            {
                intarr[i] = int.Parse(strarr[i]);
            }
        }
        public int calcMax(int[] arr)
        {
            if (arr.Length < 1)
            {
                throw new Exception("error");
            }
            int temp = arr[0];
            for(int i = 0; i < arr.Length; i++)
            {
                if (arr[i] > temp)
                {
                    temp = arr[i];
                }
            }
            return temp;
        }
        public int calcMin(int[] arr)
        {
            if (arr.Length < 1)
            {
                throw new Exception("error");
            }
            int temp = arr[0];
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] < temp)
                {
                    temp = arr[i];
                }
            }
            return temp;
        }

        public double calcAver(int[] arr)
        {
            if (arr.Length < 1)
            {
                throw new Exception("error");
            }
            double temp = 0;
            for(int i = 0; i < arr.Length; i++)
            {
                temp += arr[i];
            }
            return temp / arr.Length;
        }

        private void OnButtonClicked(object sender, EventArgs e)
        {
            try
            {
                string input = textBox4.Text;
                string[] strarr = input.Split(' ');
                int[] intarr = new int[strarr.Length];
                StrToInt(intarr, strarr);
                textBox1.Text = Convert.ToString(calcMax(intarr));
                textBox2.Text = Convert.ToString(calcMin(intarr));
                textBox3.Text = Convert.ToString(calcAver(intarr));

            }catch(Exception a)
            {
                MessageBox.Show("输入内容有误，请重新输入！");
            }
            

        }


    }
}
